using UnityEngine;

public class BackgroundMoveSky : MonoBehaviour
{
	public static int currentSkin;

	public Sprite[] skin = new Sprite[0];

	private SpriteRenderer render;

	private CameraGame gameCamera;

	private Vector3 startPosition = default(Vector3);

	private Vector3 targetPosition = default(Vector3);

	private float distMove;

	private void Start()
	{
		if (currentSkin == 0)
		{
			currentSkin = UnityEngine.Random.Range(0, skin.Length * 3);
		}
		currentSkin++;
		render = GetComponent<SpriteRenderer>();
		render.sprite = skin[currentSkin % skin.Length];
		render.flipX = (Mathf.Floor(currentSkin / skin.Length) % 2f == 0f);
		if (render.flipX)
		{
			render.transform.localPosition += new Vector3(Mathf.Floor((float)render.sprite.texture.width / render.sprite.pixelsPerUnit * 100f) / 100f, 0f, 0f);
		}
		gameCamera = GetComponentInParent<CameraGame>();
		distMove = (float)render.sprite.texture.width / render.sprite.pixelsPerUnit - gameCamera.width * 2f;
		startPosition = base.transform.localPosition;
		targetPosition.x = startPosition.x - distMove;
		targetPosition.y = startPosition.y;
		targetPosition.z = startPosition.z;
	}

	private void Update()
	{
		base.transform.localPosition = Vector3.Lerp(startPosition, targetPosition, gameCamera.normalDist);
	}
}
